package com.yrk.servlet;

import com.google.gson.Gson;
import com.yrk.service.KeyWordsService;
import com.yrk.service.impl.KeyWordsServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/keywords")
public class KeyWordsServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
        doPost(req, res);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("application/json; charset=utf-8");
        String keyname= request.getParameter("keyname");
        KeyWordsService keyWordsService = new KeyWordsServiceImpl();
        List<String> list = keyWordsService.search(keyname);
        System.out.println(list);
        Gson gson = new Gson();
        String json = gson.toJson(list);
        PrintWriter out = response.getWriter();
        out.print(json);
        out.flush();
    }
}
